package com.cx.service.impl;

import com.cx.mapper.DiscountMapper;
import com.cx.pojo.Discount;
import com.cx.pojo.DiscountExample;
import com.cx.service.DiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DiscountServiceImpl implements DiscountService {
    @Autowired
    DiscountMapper discountMapper;

    @Override
    public int insert(Discount discount) {
        int rows = discountMapper.insertSelective(discount);
        return rows;
    }

    @Override
    public int updateById(Integer discountId, Discount discount) {
        DiscountExample discountExample = new DiscountExample();
        DiscountExample.Criteria criteria = discountExample.createCriteria();
        criteria.andDiscountIdEqualTo(discountId);
        int rows = discountMapper.updateByExample(discount,discountExample);
        return rows;
    }

    @Override
    public int deleteById(Integer discountId) {
        DiscountExample discountExample = new DiscountExample();
        DiscountExample.Criteria criteria = discountExample.createCriteria();
        criteria.andDiscountIdEqualTo(discountId);
        int rows = discountMapper.deleteByExample(discountExample);
        return rows;
    }

    @Override
    public List<Discount> selectByCarId(Integer carId) {
        DiscountExample discountExample = new DiscountExample();
        DiscountExample.Criteria criteria = discountExample.createCriteria();
        criteria.andCarIdEqualTo(carId);
        List<Discount> discounts = discountMapper.selectByExample(discountExample);
        return discounts;
    }
    @Override
    public List<Discount> selectAll() {
        List<Discount> discounts = discountMapper.selectAll();
        return discounts;
    }
}
